
<template>
    <el-form-item :label="label"  v-if="label" class='formitem'>
        <el-radio v-model="currentValue" v-for="(item,index) in dataSource" :key="index" :label="item.optvalue">{{item.optname}}</el-radio>
    
    </el-form-item>
    <div v-else class="el-form-item__content formitem">
          <el-radio v-model="currentValue" v-for="(item,index) in dataSource" :key="index" :label="item.optvalue">{{item.optname}}</el-radio>
     </div>
   
    
    
</template>
 
<script>
    export default {
        props:['dataSource','value','label','styles','data','id','exkey'],
        name: "input-radio",
        data(){
            return {
                currentValue:this.value,
                pId:"",
                cId:"",
                first:"Y"
            }
        },
        created(){
            let ids=this.id.split(".");

            if(ids.length>1){
                let p=ids[0];
                let id_=ids[1];
                this.pId=p;
                this.cId=id_;
                this.currentValue=unescape(this.data[p][id_]);
                //this.currentValue=this.data[p][id_]=="Y"||this.data[p][id_]=="是" ? true:false;
            }
            
        },
        watch:{
            currentValue: function (val) { //currentValue值变动就向父组件传值
                let data={};
                data.id=this.id;
                data.val=val;

                if(this.pId){
                    this.$set(this.data[this.pId],this.cId,val)
                }else{
                    this.$set(this.data,this.id,val)
                }

                if(this.exkey&&this.exkey.setItem){
                    for(let i=0;i<this.exkey.setItem.length;i++){
                        let name=this.exkey.setItem[i].name;
                        let itemName=this.exkey.setItem[i].itemName;
                        let dataField=this.exkey.setItem[i].dataField;
                        let val_=this.exkey.setItem[i].val;
                        if(val_==val){
                            let isOk=true;
                            for(let n=0;n<this.data[dataField].length;n++){
                                let szi_ex1=this.data[dataField][n].szi_ex1;
                                if(szi_ex1==name){
                                    isOk=false;
                                }
                            }
                            if(isOk){
                                if(itemName){
                                    this.itemData=this.data[itemName];
                                    for(let n=0;n<this.itemData.length;n++){
                                        let szi_ex1=this.itemData[n].szi_ex1;
                                        if(szi_ex1==name){
                                            this.$set(this.data[dataField],this.data[dataField].length,this.itemData[n])
                                        }
                                    }
                                    
                                }else{
                                    let datas={}
                                    datas.addType="string";
                                    datas.itemType="";
                                    datas.nameType="";
                                    datas.val=name;
                                    datas.hour="1";
                                    datas.day="0";

                                    
                                

                                    this.$emit("funeralItemSelectEvent",JSON.stringify(datas))
                                }
                            }
                        }else{
                            if(this.first!="Y"){
                                for(let h=0;h<this.data[dataField].length;h++){
                                    let szi_ex1=this.data[dataField][h].szi_ex1;
                                    if(name==szi_ex1){
                                        this.$delete(this.data[dataField],h);
                                        break;
                                    }
                                }
                            }
                            
                        }
                        
                        
                        
                    }
                }
                this.first="N"
                //this.$emit('input',JSON.stringify(data));
                //this.$emit('on-change',JSON.stringify(data));
            },
            value:function (val) { //对值进行验证
                
            }
        }
    }
</script>
<style scoped>

.el-radio{
    margin-right:10px;
}

.formitem>>>.el-radio__inner{
    border:1px solid #5c5b5b;
}

</style>